<script>
export default {
  name: "MyFooter",
  props:['todoList'],
  computed:{
    total(){
      return this.todoList.length;
    },
    done(){
      return this.todoList.reduce(function(prev,todo){
        return prev + (todo.done ? 1:0);
      },0)
    },
    isAll2(){
      return this.total=== this.done && this.todoList.length;
    },
    isAll:{
      get(){
        return this.total=== this.done && this.todoList.length;
      },
      set(value){
        this.$emit('allDoneOrNot',value)
        //this.allDoneOrNot(value)
      }
    }
  },
  methods:{
    allOrNot(e){
      this.allDoneOrNot(e.target.checked)
    },
    deleteAllDone(){
      this.$emit('deleteAllDone')
    }
  }
}
</script>

<template>
  <div class="todo-footer" v-show="total">
    <label>
<!--      <input type="checkbox" :checked="isAll2" @click="allOrNot"/>-->
      <input type="checkbox" v-model="isAll"/>
    </label>
    <span>
          <span>已完成{{done}}</span> / 全部{{total}}
        </span>
    <button class="btn btn-danger" @click="deleteAllDone">清除已完成任务</button>
  </div>
</template>

<style scoped>
.todo-footer {
  height: 40px;
  line-height: 40px;
  padding-left: 6px;
  margin-top: 5px;
}

.todo-footer label {
  display: inline-block;
  margin-right: 20px;
  cursor: pointer;
}

.todo-footer label input {
  position: relative;
  top: -1px;
  vertical-align: middle;
  margin-right: 5px;
}

.todo-footer button {
  float: right;
  margin-top: 5px;
}

</style>